﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/*
 场景题：快餐店套餐构建器
 场景描述：
​     在一个快餐店，常见的套餐包括汉堡（Burger）和冷饮（Cold Drink）。
     为了满足不同客户的需求，你决定使用建造者模式来构建这些套餐。套餐的组成包括不同类型的汉堡和冷饮，每种食物都需要不同的包装。
 */
namespace CS_BEGINNER_TO_PROFICIENT.DesignPatterns.CreationMode.BuilderPattern
{
    public class Meal
    {
        private List<Item> items = new List<Item>();

        public void AddItem(Item item)
        {
            items.Add(item);
        }

        public float getCost()
        {
            float cost = 0.0f;
            foreach (var i in items)
            {
                cost += i.Price;
            }
            return cost;
        }

        public void ShowItems()
        {
            foreach (var i in items)
            {
                Console.Write("Items: " + i.Name);
                Console.Write(",Packing: " + i.Packing.Pack());
                Console.WriteLine(",Price: " + i.Price);
            }
        }
    }

    public interface Packing
    {
        string Pack();
    }

    public class Box : Packing
    {
        public string Pack() => "Box";
    }

    public class Bottle : Packing
    {
        public string Pack() => "Bottle";
    }

    public interface Item
    {
        string Name { get; }
        Packing Packing { get; }
        float Price { get; }
    }

    public abstract class Burger : Item
    {
        public abstract string Name { get; }
        public Packing Packing => new Box();
        public abstract float Price { get; }
    }

    public class VeBurger : Burger
    {
        public override string Name => "Veg Burger";

        public override float Price => 25.0f;
    }

    public class ChickenBurger : Burger
    {
        public override string Name => "Chicken Burger";
        public override float Price => 50.5f;
    }

    public abstract class ColdDrink : Item
    {
        public abstract string Name { get; }

        public Packing Packing => new Bottle();

        public abstract float Price { get; }
    }

    public class Coke : ColdDrink
    {
        public override string Name => "Coke";

        public override float Price => 30.0f;
    }

    public class Pepsi : ColdDrink
    {
        public override string Name => "Pepsi";

        public override float Price => 35.0f;
    }

    public class MealBuilder
    {
        public Meal PrePareVegMeal()
        {
            Meal meal = new Meal();
            meal.AddItem(new VeBurger());
            meal.AddItem(new Coke());
            return meal;
        }

        public Meal PrePareNonVegMeal()
        {
            Meal meal = new Meal();
            meal.AddItem(new ChickenBurger());
            meal.AddItem(new Pepsi());
            return meal;
        }
    }
}
